<?php

/**
 * Created by IntelliJ IDEA.
 * User: keke
 * Date: 18-10-18
 * Time: 下午1:45
 */
session_start();
include "./congfig/config.php";
include "./lib/common.php";

$username = $_POST['username'];
$passwd = enpasswd($_POST['passwd']);
$username = $conn->real_escape_string($username);
$sql = "select * from users where username  = '$username'  ";
$query = $conn->query($sql);
$result = $query->fetch_array();
if ($result['passwd'] == $passwd) {
    if (isset($_SESSION['loginflag'])) {
        alertMes("已登录", "index.php");
    }
    $_SESSION['loginflag'] = $result['uid'];
    $_SESSION['username'] = $result['username'];
    $_SESSION['rank'] = $result['rank'];
    switch ($_SESSION['rank']) {
        case 0:
            alertMes("登录成功", "students/owner-myProject.php");
            break;
        case 1:
            alertMes("登录成功", "teacher/project-list.php");
            break;
        case 2:
            alertMes("登录成功", "./admin/project-list.php");
            break;
    }


} else {
    alertMes("登录失败,密码错误或用户不存在！", "login.php");
}
